package edu.westga.vocalengineer.audio.gui;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

import edu.westga.vocalengineer.audio.transforms.ChorusTransform;

/**
 * ChorusGuiTransform
 *   Implements a ChorusTransform with an options panel.
 * @author mfarmer2
 *
 */
public class ChorusGuiTransform 
	extends ChorusTransform 
	implements IGuiTransform {
	
	private JPanel optionsPanel;
	private JCheckBox chorusEnabledCheck;
	private JTransformSliderPanel chorusNumberSlider;
	private JTransformSliderPanel chorusDelaySlider;
	
	/**
	 * Creates a ChorusGuiTransform.  Initializes to some
	 * default values.
	 */
	public ChorusGuiTransform() {
		super(3,1000);
		optionsPanel = new JPanel();
		chorusEnabledCheck = new JCheckBox("Enable Chorus Transform");
		chorusNumberSlider = new JTransformSliderPanel("Voices:", 1, 10, 3);
		chorusDelaySlider = new JTransformSliderPanel("Delay (samples):", 1, 8000, 1000);
		JPanel tempPanel = new JPanel();
		tempPanel.setLayout(new BoxLayout(tempPanel, BoxLayout.PAGE_AXIS));
		tempPanel.add(chorusNumberSlider);
		tempPanel.add(chorusDelaySlider);
		optionsPanel.add(chorusEnabledCheck);
		optionsPanel.add(Box.createRigidArea(new Dimension(20,20)));
		optionsPanel.add(tempPanel);
		optionsPanel.setBorder(BorderFactory.createLineBorder(Color.black));
	}
	
	/**
	 * See AudioTransform.execute; applies a transform
	 * by updating the current state to match the panel.
	 */
	@Override
	public short[] exectueWithGuiOptions(short[] samples) {
		if(!chorusEnabledCheck.isSelected()) return samples;
		chorusNumber = chorusNumberSlider.getValue();
		chorusDelay = chorusDelaySlider.getValue();
		return execute(samples);
	}

	/**
	 * Returns the options JPanel.
	 */
	@Override
	public JPanel getOptionsPanel() {
		return optionsPanel;
	}
	
}
